package com.jim.healio.agents;

import com.jim.healio.dto.Message;
import lombok.Data;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.converter.BeanOutputConverter;

@Data
public abstract class Agent {

    /**
     * 角色
     */
    private String role;

    /**
     * 姓名
     */
    private String name;

    /**
     * 大模型客户端
     */
    private ChatClient chatClient;

    private BeanOutputConverter<Message> beanOutputConverter;

    public Agent(String role, String name, ChatClient chatClient) {
        this.role = role;
        this.name = name;
        this.chatClient = chatClient;
        beanOutputConverter = new BeanOutputConverter<>(Message.class);
    }

    /**
     * 运行方法
     * @param prompt
     * @return
     */
    public Message invoke(String prompt) {
        String content = chatClient
                .prompt(prompt)
                .call()
                .content();

        assert content != null;
        return beanOutputConverter.convert(content);
    }

}
